package com.project.controller;

import com.project.bean.SpeakBean;
import com.project.bean.UserBean;
import com.project.service.ISpeakService;
import com.project.util.JWTUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("speak")
public class SpeakController {
    @Autowired
    private ISpeakService service;
    @RequestMapping("add")
    public String add(String content, int productId,
                    HttpServletRequest request){
        String token = request.getHeader("token");
        UserBean user =  (UserBean) JWTUtil.getTokenInfo(token,"user",UserBean.class);

        SpeakBean speak = new SpeakBean(user.getId(),productId,content);
        //调用业务方法完成添加
        service.addSpeak(speak);

        return "ok";
    }
}
